const request = require('supertest');
const app = require('../app');

describe('API Endpoints', () => {
  // 测试注册接口
  it('should register a new member', async () => {
    const response = await request(app)
      .post('/api/register')
      .send({
        name: '张三',
        email: 'zhangsan@example.com',
        password: 'SecurePass123',
        phone: '13912345678'
      });
    expect(response.statusCode).toBe(201);
  });

  // 测试登录接口
  it('should return JWT token on valid login', async () => {
    const response = await request(app)
      .post('/api/login')
      .send({
        email: 'zhangsan@example.com',
        password: 'SecurePass123'
      });
    expect(response.body.token).toBeDefined();
    expect(response.body.member.email).toBe('zhangsan@example.com');
  });
});